import {_decorator, v2, Animation, Component, Node, CircleCollider2D, Collider2D, RigidBody2D, Vec2} from 'cc';
import {StateMachine} from "db://assets/Script/State/StateMachine";
import {StateEnum} from "db://assets/Script/Enums/StateEnum";
import {PlayerController} from "db://assets/Script/Actor/controller/PlayerController";

const {ccclass, property, requireComponent, disallowMultiple} = _decorator;

@ccclass('Actor')
@requireComponent(RigidBody2D)//2D刚体
@requireComponent(CircleCollider2D)//2D圆形碰撞盒
//限制在同一个节点上只能添加一个同类型的组件或子组件
@disallowMultiple(true)
export class Actor extends Component {
    rigidBody2D: RigidBody2D | null = null
    circleCollider2D: Collider2D | null = null
    //状态管理器
    stateManager: StateMachine<StateEnum> = new StateMachine<StateEnum>();
    //动画组件
    @property(Animation)
    animation: Animation = null!
    //输入的向量
    _input: Vec2 = v2()
    //默认移动速度
    linearSpeed: number = 3;

    //是否是死亡状态
    dead: boolean = false;

    start() {
        this.rigidBody2D = this.node.getComponent(RigidBody2D)
        this.circleCollider2D = this.node.getComponent(Collider2D)

    }

    update(deltaTime: number) {
        this.stateManager.update(deltaTime)
    }

    set input(vector2: Vec2) {
        console.log("输入向量：", vector2.x, vector2.y)
        this._input.set(vector2.x, vector2.y)
    }

    get input(): Vec2 {
        console.log("获取向量", this._input)
        return this._input
    }
}


